//
//  MainHeaderView.m
//  GiftItems
//
//  Created by lanou3g on 15/9/18.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MainHeaderView.h"

@implementation MainHeaderView

- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        
        NSMutableArray *insterArray = [NSMutableArray arrayWithArray:imageArray];
        
        //讲imageArray最后一张查到insterArray的第0位
        [insterArray insertObject:[imageArray objectAtIndex:imageArray.count - 1] atIndex:0];
        //讲imageArray第0张插入到最后
        [insterArray insertObject:[imageArray objectAtIndex:0] atIndex:insterArray.count];
        //设置ScrollerView的contenSize
        self.contentSize = CGSizeMake(kWidth *[insterArray count], 0);
        self.pagingEnabled = YES;
        self.showsHorizontalScrollIndicator = YES;
        self.bounces = NO;
        self.delegate = delegate;
        self.contentOffset = CGPointMake(kWidth, 0);
        //循环创建ImageView
        for (int i = 0; i < insterArray.count; i++) {
            TapImageView *touchImage = [[TapImageView alloc] initWithFrame:CGRectMake(kWidth * i, 0, kWidth, self.bounds.size.height) taget:delegate action:action];
            
            [self addSubview:touchImage];
        }
        
        
        
        
    }
    
    
    
    
    
    return self;
    
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
